﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.SqlClient;

public partial class BalanceCenter_Net2 : PageBase
{
    public string[] MemberBack = new string[7];
    public string[] NextUserID = new string[7];
    public string[] NextNetID = new string[7];

    protected void Page_Load(object sender, EventArgs e)
    {
        long id = ShoveEL._Convert.StrToLong(this.Request["id"], -1);
        long netID = ShoveEL._Convert.StrToLong(this.Request["netID"], -1);
        if ((id < 0) && (netID < 0))
        {
            id = _User.ID;
        }

        BindDataForNets_2NameList();

        BindData(id, netID);
    }

    #region Web 窗体设计器生成的代码

    override protected void OnInit(EventArgs e)
    {
        isRequestLogin = true;
        RequestLoginPage = "BalanceCenter/Net2.aspx";
        //RequestCompetences = Competences.BuildCompetencesList(Competences.Administrator);

        base.OnInit(e);
    }

    #endregion

    private void BindDataForNets_2NameList()
    {
        //if (!_User.ManagementRights && !_User.SuperManagementRights)
        //  return;
        if (_User.ID == 1)
        {
            long Count = DAL.Tables.T_Nets_2.GetCount("");

            labCount.Visible = true;
            labCount.Text = "当前分红网点位总数： " + Count.ToString() + " <a href='AdminNets_2List.aspx'>查看分红网名单列表</a>";
        }
    }

    private void BindData(long id, long netID)
    {
        //if ((_User.ManagementRights) && (_User.SuperManagementRights))
        //{
        //    DataTable dt = ShoveEL.Database.MSSQL.Select("select [userID] from Nets_2 where ParentnetID = -1");
        //}

        DataSet ds = DAL.Procedures.P_GetNetForNets_2.Open(id, netID);

        if (ds == null)
        {
            PublicFunction.GoError(ErrorNumber.DataReadWrite, "数据读写错误", this.GetType().BaseType.FullName);

            return;
        }

        if (ds.Tables.Count == 0)
        {
            PublicFunction.GoError(ErrorNumber.NoData, "对不起，消费者暂时不在分红网网络上", this.GetType().BaseType.FullName);

            return;
        }

        if (ds.Tables.Count == 0)
        {
            for (int i = 0; i < 7; i++)
            {
                MemberBack[i] = "MemberBack0.jpg";
            }

            ShoveEL._Web.JavaScript.Alert(this.Page, "此消费者暂时不在分红网网络上。");

            return;
        }

        DataTable dt = ds.Tables[0];
        for (int i = 0; i < 7; i++)
        {
            DataRow[] dr = dt.Select("Locate=" + (i + 1).ToString());
            if (dr.Length < 1)
            {
                MemberBack[i] = "#ffffff";
            }
            else
            {
                int UserTypeGold = 0;   //星星
                int UserType = ShoveEL._Convert.StrToInt(dr[0]["UserType"].ToString(), 1);

                long userID = ShoveEL._Convert.StrToLong(dr[0]["id"].ToString(), -1);
                if (userID == -1)
                {
                    MemberBack[i] = "#ffffff";
                }
                else
                {
                    if (UserType == 1)
                    {
                        MemberBack[i] = "#fad6d8";
                        UserTypeGold = 1;
                    }
                    else if (UserType == 3)
                    {
                        MemberBack[i] = "#cbf6e2";
                        UserTypeGold = 2;
                    }
                    else if (UserType == 5)
                    {
                        MemberBack[i] = "#f8f7c9";
                        UserTypeGold = 3;
                    }                  
                    else
                    {
                        MemberBack[i] = "red";
                        UserTypeGold = 4;
                    }

                    //((Label)this.FindControl("labBDZX" + (i + 1).ToString())).Text = (ShoveEL._Convert.StrToBool(dr[0]["isSurrogate"].ToString(), false) ? "<img src='../Images/Surrogate.gif' border='0'>" : "");
                    ((Label)this.FindControl("labName" + (i + 1).ToString())).Text = "<a class='li8' href='Net2.aspx?netID=" + dr[0]["id"].ToString() + "'>" + dr[0]["Name"].ToString() + "</a>";

                    string Img = "";
                    for (int j = 1; j <= UserTypeGold; j++)
                        Img += "<img src='../Images/gold.gif' border='0'>";
                    ((Label)this.FindControl("labUserType" + (i + 1).ToString())).Text = Img;
                }

                if (i >= 3)
                {
                    if (ShoveEL._Convert.StrToBool(dr[0]["HasSub"].ToString(), false))
                    {
                        NextNetID[i] = dr[0]["id"].ToString();
                        NextUserID[i] = dr[0]["userID"].ToString();
                        ((System.Web.UI.WebControls.Image)this.FindControl("imgNext" + (i + 1).ToString())).Visible = true;
                    }
                }
            }
        }

        if (ds.Tables.Count >= 2)
        {
            dt = ds.Tables[1];
            for (int i = 0; i < dt.Rows.Count; i++)
            {
                labLocate.Text += "<a class='li8' href='Net2.aspx?netID=" + dt.Rows[i]["id"].ToString() + "&id=" + dt.Rows[i]["userID"].ToString() + "'>" + "排位" + (i + 1).ToString() + "</a>&nbsp;&nbsp;";
            }
        }
    }
}